﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;
using DB.SqlHelper;
using Framework.Common.Common;
using Mode;


namespace Framework.DataAccess
{
    public class Answer
    {
        public string title { get; set; }
        public bool right { get; set; }
    }

    public class TopicEx : topic_table
    {
        private List<Answer> anserlist = new List<Answer>();
        public List<Answer> Answer
        {
            get {
                DbInstance db = DbManager.GetDbInstance();
                DataTable dt = db.ExecuteDataTableBySql("select answer as 'title' , [right]  from answer_table where topic=" + this.id);
                foreach (DataRow row in dt.Rows)
                {
                    Answer tmp = new Answer();
                    tmp.title = row["title"].ToStr();
                    tmp.right = (row["right"].ToInt()==1 ? true : false);
                    anserlist.Add(tmp);
                }

                return anserlist;
            }
        }
    }

    public class ExportTopic
    {
        public static List<TopicEx> GetTopic(int type)
        {
            List<TopicEx> result = new List<TopicEx>();

            DbInstance db = DbManager.GetDbInstance();
            DataTable dt = db.ExecuteDataTableBySql("select * from topic_table where [type]="+type);
            foreach (DataRow row in dt.Rows)
            {
                TopicEx tmp = new TopicEx();
                tmp.id = row["id"].ToInt();
                tmp.title = row["title"].ToStr();
                result.Add(tmp);
            }

            return result;
        }
    }
}
